package com.tsystems.train.bean;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.tsystems.train.entity.Train;

public class TrainTableDataModel extends ListDataModel<Train> implements
		SelectableDataModel<Train>, Serializable {

	

	
	private static final long serialVersionUID = 3170725918988239610L;

	public TrainTableDataModel() {
	}

	public TrainTableDataModel(List<Train> data) {
		super(data);
	}

	@SuppressWarnings("unchecked")
	public Train getRowData(String rowKey) {
		List<Train> trains = (List<Train>) getWrappedData();

		for (Train train : trains) {
			String key = train.getNumber();
			if (key.equals(rowKey))
				return train;
		}

		return null;
	}

	public Object getRowKey(Train train) {
		return train.getNumber();
	}
}
